package com.lzm.ydpt.module.mall.activity;

import android.os.Bundle;
import android.view.View;

import androidx.viewpager.widget.ViewPager;

import com.byt.framlib.base.BaseActivity;
import com.byt.framlib.base.BaseFragment;
import com.byt.framlib.base.TabFragmentAdapter;
import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.commonutils.DisplayUtil;
import com.byt.framlib.commonwidget.NormalTitleBar;
import com.byt.framlib.commonwidget.flycotab.SlidingTabLayout;
import com.lzm.ydpt.R;
import com.lzm.ydpt.module.mall.fragment.MallOrderListFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 商城订单列表
 */
public class MallOrderListActivity extends BaseActivity {

    public static final String INP_ORDER_POSITION = "order_position";
    public static final String INP_ORDER_JUMPMODE = "order_jumpmode";

    @BindView(R.id.ntb_order_list)
    NormalTitleBar ntb_order_list;
    @BindView(R.id.tab_order_list)
    SlidingTabLayout tab_order_list;

    @BindView(R.id.vp_order_list)
    ViewPager vp_order_list;
    private List<String> titleList = new ArrayList<>();
    private ArrayList<BaseFragment> fragments = new ArrayList<>();

    private int position = 0;
    /**
     * 0 正常跳转
     * 1 从支付页跳转过来的，返回上一级需要返回到首页
     */
    private int jumpMode = 0;

    @Override
    public int getLayoutId() {
        return R.layout.activity_mall_order_list;
    }

    @Override
    public BasePresenter initPreData() {
        return null;
    }

    @Override
    public void initView() {
        position = getIntent().getIntExtra(INP_ORDER_POSITION, 0);
        jumpMode = getIntent().getIntExtra(INP_ORDER_JUMPMODE, 0);
        initTitle();
        titleList.clear();
        fragments.clear();
        titleList.add("全部");
        titleList.add("待付款");
        titleList.add("待收货");
        titleList.add("已完成");
        titleList.add("已取消");
        // 	订单状态 0：全部 1:待付款，2：待收货，3：已完成 4:已取消
        fragments.add(MallOrderListFragment.newInstance(0));
        fragments.add(MallOrderListFragment.newInstance(1));
        fragments.add(MallOrderListFragment.newInstance(2));
        fragments.add(MallOrderListFragment.newInstance(3));
        vp_order_list.setAdapter(new TabFragmentAdapter(getSupportFragmentManager(), fragments, titleList));
        vp_order_list.setOffscreenPageLimit(3);
        vp_order_list.addOnPageChangeListener((new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        }));
        tab_order_list.setTabWidthPx(DisplayUtil.getScreenWidth(this) / 5);
        tab_order_list.setViewPager(vp_order_list);
        tab_order_list.setCurrentTab(position);
    }


    private void initTitle() {
        ntb_order_list.setTitleText("我的订单");
        ntb_order_list.setOnBackListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (jumpMode == 1) {
                    Bundle mainBundle = new Bundle();
//                    mainBundle.putInt(MallMainActivity.INP_MAIN_POSITION, 4);
                    openActivity(MallMainActivity.class, mainBundle);
                }
                finish();
            }
        });
    }
}